#include "Common.h"

void LUAPlayer::Broadcast(const char* string)
{
	if(plr)
		plr->BlueSystemMessage(string);
	else
		Log->Warning("LUAEngine", "Tried to broadcast to a nil-player!");
}

void LUAPlayer::CreateGossipMenu(ui32 textid, LUAUnit unit)
{
	if(menu)
		delete menu;
	menu = new GossipMenu(textid, unit.cr->GetGUID());
}

void LUAPlayer::AddGossipItem(ui32 icon, const char* text, ui32 cas)
{
	if(menu)
		menu->AddMenuItem(icon, (char*)text, cas);
}

void LUAPlayer::SendGossipMenu()
{
	if(menu && plr)
		menu->Send(plr);
}

LUAMoney LUAPlayer::GetMoney()
{
	Useable::Money mon = Useable::ConvertToMoney(plr->GetUI32Value(PLAYER_FIELD_COINAGE));
	return LUAMoney(mon.gold, mon.silver, mon.copper);
}

scope LUAPlayer::RegisterLUAPlayer()
{
	return 
		class_<LUAPlayer>("LUAPlayer")
		.def("Broadcast", &LUAPlayer::Broadcast)
		.def("GetName", &LUAPlayer::GetName)
		.def("CreateGossipMenu", &LUAPlayer::CreateGossipMenu)
		.def("AddGossipItem", &LUAPlayer::AddGossipItem)
		.def("SendGossipMenu", &LUAPlayer::SendGossipMenu)
		.def("GossipEnd", &LUAPlayer::GossipEnd)
		.def("GetMoney", &LUAPlayer::GetMoney)
		.def("SendPacket", &LUAPlayer::SendPacket);
}